Skip to content

feat: disable OpenCode compaction and add proactive token budget pruning#21

Merged
tuanhung303 merged 1 commit intomasterfrom
feat/disable-opencode-compaction
Feb 9, 2026
Merged

feat: disable OpenCode compaction and add proactive token budget pruning#21
tuanhung303 merged 1 commit intomasterfrom
feat/disable-opencode-compaction

Conversation

@tuanhung303
Copy link
Owner

Summary

  • Disables OpenCode's built-in compaction via the config hook — prevents OpenCode from summarizing and dropping conversation history before the plugin can process it
  • Adds proactivePrune strategy that manages token budget at the plugin level: prunes old tool outputs at 70% context usage, adds reasoning block pruning at 85%
  • Safety net compacting hook preserves plugin state (active todos, tracked files, pruning stats) in any compaction summary if compaction is ever re-enabled

Problem

OpenCode's auto-compaction runs before the plugin's experimental.chat.messages.transform hook, so when it triggers it drops all history — overriding the plugin's granular pruning. The plugin never sees the messages OpenCode already removed.

Solution

  1. Config hook sets compaction: { auto: false, prune: false } so OpenCode never triggers its own compaction
  2. proactivePrune strategy replaces OpenCode's role in managing context window pressure with configurable thresholds
  3. compacting hook acts as a last-resort safety net if a user re-enables compaction manually

Files Changed

File Change
index.ts Config hook + compacting safety net hook
lib/strategies/proactive-prune.ts NEW — proactive pruning strategy (~235 lines)
lib/strategies/index.ts Export proactivePrune
lib/hooks.ts Register proactivePrune in PRUNE_STRATEGIES pipeline
lib/config/schema.ts TokenBudgetSchema with configurable thresholds
lib/config/defaults.ts Default token budget values
tests/e2e/proactive-pruning.test.ts NEW — 13 E2E tests
tests/hooks.test.ts Mock fix for new strategy
tests/integration/opt-in-defaults.test.ts Mock fix for new strategy

Test Results

  • 32/32 test files pass
  • 570/570 tests pass (13 new)
  • Build clean, npm link verified

Replace OpenCode's built-in compaction (which drops all history before a summary)
with a plugin-managed proactive pruning strategy that preserves granular context.

- Config hook disables OpenCode auto-compaction and tool output pruning
- New proactivePrune strategy: at 70% context prunes old tool outputs, at 85% also prunes reasoning blocks
- Compacting safety net hook preserves plugin state (todos, tracked files, stats) if compaction ever triggers
- Configurable thresholds via TokenBudget schema (warningThreshold, criticalThreshold, targetPercent, protectedRecentTurns)
- 13 E2E tests covering all threshold and config scenarios
@tuanhung303 tuanhung303 merged commit 280347f into master Feb 9, 2026
3 checks passed
@tuanhung303 tuanhung303 deleted the feat/disable-opencode-compaction branch February 9, 2026 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant